<template>
	<div id="adddevicelibrary" class="same-change-oldstyle">
		<div class="same-head-box" style="border: none;">
			<div class="saem-seat-box">
				<div class="saem-seat-left">
					<span>当前位置：</span>
					<el-breadcrumb separator-class="el-icon-arrow-right">
						<el-breadcrumb-item>设备中心</el-breadcrumb-item>
						<el-breadcrumb-item :to="{ path: '/librarylist' }">主板库管理</el-breadcrumb-item>
						<el-breadcrumb-item>主板入库</el-breadcrumb-item>
					</el-breadcrumb>
				</div>
				<div class="saem-seat-right">
					<!-- <button class="same-search-btns same-search-export" @click="RefreshFun">刷新</button> -->
					<button class="same-search-btns" @click="returnBack">返回</button>
				</div>
			</div>


			<div class="device-title"><i class="el-icon-setting"></i>设备信息入库</div>


			<div class="flex-row">
				<span class="label">设备编号</span>
				<el-input size="medium" v-model="equipment_number" placeholder="请输入设备编号(主板获取)" maxlength="32"></el-input>
			</div>
			<div class="flex-row">
				<span  class="label">主板型号</span>
				<el-select style="flex: 1;" size="medium" v-model="mainboard_type_number" placeholder="请选择主板型号">
					<el-option v-for="item in mainboard" :key="item.id" :label="item.name" :value="item.number"></el-option>
				</el-select>
			</div>
			<!-- <button class="same-search-btns" type="button" @click="submitForm()">确认</button> -->
			<el-button @click="submitForm" class='add-btn' size="medium" type="primary">确 认</el-button>
		</div>

	</div>
</template>

<script>
	import { regionDataPlus, CodeToText } from 'element-china-area-data';
	export default {
		name: 'adddevicelibrary',
		data: function () {
			return {
				equipment_number: '',
				mainboard_type_number: '', //主板名称
				mainboard: [] //主板
			};
		},
		inject: [
			'reload'
		],
		methods: {
			RefreshFun() {
				// 调用reload方法，刷新整个页面
				this.reload()
			},
			//返回
			returnBack() {
				this.$router.back(-1);
			},
			chooseMainboard(name) {
				this.mainboard_type_number = name;
			},
			// 设备类型
			getEquipment_type() {
				this.$post({
					url: 'Common/Common/getEquipmentType',
					data: {},
					success: data => {
						this.equipment_type_list = data.data;
					}
				});
			},

			// 添加设备确认按钮
			submitForm: function () {
				var that = this;
				// 获取参数
				var equipment_number = that.equipment_number;
				var mainboard_type_number = that.mainboard_type_number;

				if (equipment_number == '') {
					that.$message.error('设备编号不能为空');
					return false;
				}

				// Ajax请求
				that.$post({
					url: 'Partner/Equipment/addDevicelibrary',
					data: {
						equipment_number: equipment_number,
						mainboard_type_number: mainboard_type_number
					},
					success: data => {
						if (data.code == 1000) {
							that.$router.push({ path: '/librarylist' });
							that.$message.success(data.message);
						} else {
							that.$message.error(data.message);
						}
					}
				});
			},
			//获取主板型号
			getMainboard() {
				this.$post({
					url: 'Common/Common/getEquipmentMainboard',
					success: res => {
						if (res.code == 1000) {
							this.mainboard = res.data;
						}
					}
				});
			},
			openmap: function () { }
		},
		mounted() { },
		watch: {},
		created() {
			this.getMainboard(); //获取主板型号列表
		}
	};
</script>

<style scoped>
	.device-title {
		margin-top: 20px;
		color: #2C5586;
	}

	.device-title i {
		margin-right: 10px;
	}

	.flex-row {
		display: flex;
		align-items: center;
		width: 400px;
		margin-top: 20px;
	}


	.flex-row .label {
		width: 90px;
		flex-shrink: 0;
	}
	.add-btn{
		margin-top: 20px;
	}
</style>